<template>
  <div class="role-management">
    <el-card>
      <template #header>
        <div class="card-header">
          <span>角色管理</span>
        </div>
      </template>
      <div class="role-content">
        <!-- 角色管理内容区域 -->
        <el-table :data="roleList" style="width: 100%">
          <el-table-column prop="id" label="角色ID" width="80" />
          <el-table-column prop="name" label="角色名称" width="180" />
          <el-table-column prop="description" label="角色描述" />
          <el-table-column prop="createTime" label="创建时间" width="180" />
          <el-table-column label="操作" width="150" fixed="right">
            <template #default="scope">
              <el-button size="small" @click="handleEdit(scope.row)">编辑</el-button>
              <el-button size="small" type="danger" @click="handleDelete(scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { ElMessage } from 'element-plus'

// 角色列表数据
const roleList = ref([
  { id: 1, name: '管理员', description: '系统管理员', createTime: '2023-01-01' },
  { id: 2, name: '编辑', description: '内容编辑', createTime: '2023-01-02' },
  { id: 3, name: '访客', description: '只读权限', createTime: '2023-01-03' },
])

// 挂载时执行
onMounted(() => {
  // 实际项目中这里会调用API获取角色数据
  // loadRoleList()
})

// 加载角色列表
const loadRoleList = async () => {
  try {
    // 模拟API请求
    // const response = await request.get('/api/roles')
    // roleList.value = response.data
    ElMessage.success('角色列表加载成功')
  } catch (error) {
    ElMessage.error('角色列表加载失败')
    console.error('加载角色列表失败:', error)
  }
}

// 编辑角色
const handleEdit = (row: any) => {
  ElMessage.info(`编辑角色: ${row.name}`)
  // 实际项目中这里会打开编辑对话框
}

// 删除角色
const handleDelete = (row: any) => {
  ElMessage.info(`删除角色: ${row.name}`)
  // 实际项目中这里会显示确认对话框
}
</script>

<style scoped lang="scss">
.role-management {
  padding: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.role-content {
  margin-top: 20px;
}
</style>